cd "C:\Users\creto\Desktop\chinese_students_2017\Submissions\ReStat\Replication Files 2022"

clear
set more off

cap log close


*load data
	use ./kswxy_data, clear

	drop if citycode==.


*set controls
global controls "chinatariff00_expw97 share_revenue_exw97 inputtariff02_expw97 contract_cons_exw97" 
label var contract_cons_exw97 "Contract Intensity"
label var share_revenue_exw97 "Export License"
label var chinatariff00_expw97 "Import Tariffs"
label var inputtariff02_expw97 "Input Tariffs"
label var ln_chinatariff_expw97 "Annual Import Tariffs"
label var ln_inputtariff_expw97 "Annual Input Tariffs"
	

*calculation for interquartile effect	
	sum iv_ntr if year==2013 & balanced==1, de
	local iqr_ivntr = r(p75) - r(p25)
	eststo clear

*main regressions
	eststo A: reg shc_stud_tot_0213 iv_ntr if year==2013 , cluster(citycode)
	estadd ysumm
	estadd local iqreffect = round(`iqr_ivntr'*_b[iv_ntr]*1000,1)
	eststo B: reg shc_stud_tot_0213 iv_ntr chinatariff00_expw97 if year==2013 & balanced==1, cluster(citycode)
	estadd ysumm
	estadd local iqreffect = round(`iqr_ivntr'*_b[iv_ntr]*1000,1)
	eststo C: reg shc_stud_tot_0213 iv_ntr chinatariff00_expw97 share_revenue_exw97 if year==2013 & balanced==1, cluster(citycode)
	estadd ysumm
	estadd local iqreffect = round(`iqr_ivntr'*_b[iv_ntr]*1000,1)
	eststo D: reg shc_stud_tot_0213 iv_ntr chinatariff00_expw97 share_revenue_exw97 inputtariff02_expw97 if year==2013 & balanced==1, cluster(citycode)
	estadd ysumm
	estadd local iqreffect = round(`iqr_ivntr'*_b[iv_ntr]*1000,1)
	eststo E: reg shc_stud_tot_0213 iv_ntr $controls if year==2013 & balanced==1 , cluster(citycode)
	estadd ysumm
	estadd local iqreffect = round(`iqr_ivntr'*_b[iv_ntr]*1000,1)

	esttab A B C D E using "./table3.tex", replace b(3) se(3) /// 
		keep(iv_ntr $controls) star(* 0.10 ** 0.05 *** 0.01) stats(iqreffect ymean N r2, label("\textit{Interquartile Effect:}\\ \textit{$\Delta$ Students per 1m Pop.}" "Mean Dep Var." "Obs." "R2") fmt(%12.0fc %12.3fc %12.0fc %12.3fc)) ///
		mtitles("No Controls" "\shortstack{+Control for\\Import Tariffs}" "\shortstack{+Control for\\Export Licenses}" "\shortstack{+Control for\\Input Tariffs}" "\shortstack{+Control for\\Contract Intensity}") ///
		mgroups("2002-2013", pattern(1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		substitute(\_ _) label booktabs nonotes
	
